var app = sm("do_App");
var page = sm("do_Page");
var hashdata = mm("do_HashData");
var openHelper = require("helper/open");
var http = require("helper/http");
var httpSilence = require("helper/httpSilence");
var userUtil = require("helper/user");
var urlUser = require("url/user");
var nf = deviceone.sm("do_Notification");
var qqCacher = require("helper/qqCacher");
var deviceHelper = require("helper/device");
var upgradeHelper = require("helper/upgrade");
var urlPub = require("url/pub");
var imApiHelper = require("helper/imApi");
var imHelper = require("helper/im");
//创建一个External对象
var external = sm("do_External");

//andriod返回键
page.on("back", function() {
	app.closePage({"fromPage":"userMain"});
});

var layoutHead = ui("layoutHead");
var addheader = layoutHead.add("header", "source://view/reuse/header.ui", 0, 0);
//左上角-返回
var headerLeft = ui(addheader+".headerLeft");
headerLeft.on("touch", function() {
  app.closePage({"fromPage":"userMain"});
});
var header = ui("header");
header.bindData(hashdata);
hashdata.addData({
  "labelTitle" : "设置"
})
header.refreshData();

var aoutFirst = ui("aoutFirst");
var aoutSecond = ui("aoutSecond");




/*隐私设置*/
var addSecretSt = aoutFirst.add("secretSt", "source://view/reuse/form/textLabel.ui",0,0);
var secretSt = ui("secretSt");
secretSt.bindData(hashdata);
hashdata.addData({
    "labelTitle" : "隐私设置",
    "labelTipsVisible":true,
    "labelTips":"保护自己的隐私信息"
});
secretSt.refreshData();
secretSt.on("touch", function(data, e) {
	openHelper.open("source://view/user/privacy/privacy.ui");
});
/*我的屏蔽*/
var addShield = aoutFirst.add("shield", "source://view/reuse/form/textLabel.ui","secretSt");
var shield = ui("shield");
shield.bindData(hashdata);
hashdata.addData({
    "labelTitle" : "我的屏蔽",
    "labelTipsVisible":true,
    "labelTips":"屏蔽的信息用户"
});
shield.refreshData();
shield.on("touch", function(data, e) {
	openHelper.open("source://view/shield/manage/list.ui");
});
var osType = deviceHelper.getOsType();
var title = "应用升级(V"+qqCacher.currentNativeVersion()+")";
var tips = "检查更新";
if(osType==="2"){
	title = "AppleStore";
	tips = "前往苹果商店查看详情";
}
/*系统更新*/
var addSystemUpdate = aoutSecond.add("systemUpdate", "source://view/reuse/form/textLabel.ui","customerPhone");
var systemUpdate = ui("systemUpdate");
systemUpdate.bindData(hashdata);
hashdata.addData({
    "labelTitle" : title,
    "labelTipsVisible":true,
    "labelTips":tips
});
systemUpdate.refreshData();
systemUpdate.visible = true;
ui(addSystemUpdate).on("touch", function(data, e) {
	http.post(urlPub.upgrade.checkUpgrade, {"contentVer":qqCacher.currentContentVersion(),"nativeVer":qqCacher.currentNativeVersion(),"platform":osType}, function(upddata) {
		upgradeHelper.doUpgrade(upddata.pubUpgradeVo);
	});
});
if(osType==="2"){
	systemUpdate.visible = false;
	systemUpdate.refreshData();
}
/*退出登录*/
ui("logoutBtn").on("touch", function(data, e) {
	httpSilence.post(urlUser.url.login.doLogout,{}, function(data) {});
	userUtil.loginToken("");
	userUtil.userId("");
	app.fire("fireUserLogout");
	nf.toast("已退出");
	imApiHelper.logoutIM(function(){
		app.closePage({fromPage:"loginOut"});
	});
});
page.on("result", function(data) {
});

